﻿using System;
using System.Threading;

namespace Rimifier.Support
{

  /// <summary>
  /// Class RandomHelper.
  /// </summary>
  public static class RandomHelper
  {
    /// <summary>
    /// The seed counter
    /// </summary>
    private static int _seedCounter = new Random().Next();

    /// <summary>
    /// The RNG
    /// </summary>
    [ThreadStatic] private static Random _rng;

    /// <summary>
    /// Gets the instance.
    /// </summary>
    /// <value>The instance.</value>
    public static Random Instance
    {
      get
      {
        if (_rng == null)
        {
          var seed = Interlocked.Increment(ref _seedCounter);
          _rng = new Random(seed);
        }
        return _rng;
      }
    }

  }
}